package com.openroom.ui;

import org.apache.pivot.wtk.ButtonPressListener;

import com.openroom.model.ModelLocator;

public class RatingButtonListener implements ButtonPressListener {
    @Override
    public void buttonPressed(org.apache.pivot.wtk.Button button) {
        try {
            Integer value = (Integer) button.getUserData().get("RATING_VALUE");
            int prev_value = ModelLocator.getInstance().getCurrentlySelectedImage().getRatingValue();
            if (prev_value == value) {
                ModelLocator.getInstance().changeRating(0);
                return;
            }
            ModelLocator.getInstance().changeRating(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}